package com.goodving.guli.activity;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import java.lang.reflect.Method;

/**
 * Created by john on 2015/11/26.
 */

public class ff {
    public static final int f10211a = 0x99000000;
    public static String f10212b;
    private final fh f10213c;
    private boolean f10214d;
    private boolean f10215e;
    private boolean f10216f;
    private boolean f10217g;
    private View f10218h;
    private View f10219i;

    static {
        if (Build.VERSION.SDK_INT >= 19) {
            try {
                Method declaredMethod = Class.forName("android.os.SystemProperties").getDeclaredMethod("get", new Class[]{String.class});
                declaredMethod.setAccessible(true);
                f10212b = (String) declaredMethod.invoke(null, new Object[]{"qemu.hw.mainkeys"});
            } catch (Throwable th) {
                f10212b = null;
            }
        }
    }

    @TargetApi(19)
    public ff(Activity activity) {
        Window window = activity.getWindow();
        ViewGroup viewGroup = (ViewGroup) window.getDecorView();
        if (Build.VERSION.SDK_INT >= 19) {
            TypedArray obtainStyledAttributes = activity.obtainStyledAttributes(new int[]{16843759, 16843760});
            try {
                this.f10214d = obtainStyledAttributes.getBoolean(0, false);
                this.f10215e = obtainStyledAttributes.getBoolean(1, false);
                WindowManager.LayoutParams attributes = window.getAttributes();
                if ((67108864 & attributes.flags) != 0) {
                    this.f10214d = true;
                }
                if ((attributes.flags & 134217728) != 0) {
                    this.f10215e = true;
                }
            } finally {
                obtainStyledAttributes.recycle();
            }
        }
        this.f10213c = new fh(activity, this.f10214d, this.f10215e);
        if (!this.f10213c.m14878d()) {
            this.f10215e = false;
        }
        if (this.f10214d) {
            m14848a(activity, viewGroup);
        }
        if (this.f10215e) {
            m14849b(activity, viewGroup);
        }
    }

    private void m14848a(Context context, ViewGroup viewGroup) {
        this.f10218h = new View(context);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, this.f10213c.m14876b());
        layoutParams.gravity = 48;
        if (this.f10215e && !this.f10213c.m14875a()) {
            layoutParams.rightMargin = this.f10213c.m14880f();
        }
        this.f10218h.setLayoutParams(layoutParams);
        this.f10218h.setBackgroundColor(f10211a);
        this.f10218h.setVisibility(View.GONE);
        viewGroup.addView(this.f10218h);
    }

    private void m14849b(Context context, ViewGroup viewGroup) {
        FrameLayout.LayoutParams layoutParams;
        this.f10219i = new View(context);
        if (this.f10213c.m14875a()) {
            layoutParams = new FrameLayout.LayoutParams(-1, this.f10213c.m14879e());
            layoutParams.gravity = 80;
        } else {
            layoutParams = new FrameLayout.LayoutParams(this.f10213c.m14880f(), -1);
            layoutParams.gravity = 5;
        }
        this.f10219i.setLayoutParams(layoutParams);
        this.f10219i.setBackgroundColor(f10211a);
        this.f10219i.setVisibility(View.GONE);
        viewGroup.addView(this.f10219i);
    }

    public fh m14851a() {
        return this.f10213c;
    }

    public void m14852a(float f) {
        m14856b(f);
        m14861c(f);
    }

    public void m14853a(int i) {
        m14862c(i);
        m14866e(i);
    }

    public void m14854a(Drawable drawable) {
        m14858b(drawable);
        m14863c(drawable);
    }

    public void m14855a(boolean z) {
        this.f10216f = z;
        if (this.f10214d) {
            this.f10218h.setVisibility(z ? View.VISIBLE : View.GONE);
        }
    }

    @TargetApi(11)
    public void m14856b(float f) {
        if (this.f10214d && Build.VERSION.SDK_INT >= 11) {
            this.f10218h.setAlpha(f);
        }
    }

    public void m14857b(int i) {
        m14865d(i);
        m14867f(i);
    }

    public void m14858b(Drawable drawable) {
        if (this.f10214d) {
            this.f10218h.setBackgroundDrawable(drawable);
        }
    }

    public void m14859b(boolean z) {
        this.f10217g = z;
        if (this.f10215e) {
            this.f10219i.setVisibility(z ? View.VISIBLE : View.GONE);
        }
    }

    public boolean m14860b() {
        return this.f10216f;
    }

    @TargetApi(11)
    public void m14861c(float f) {
        if (this.f10215e && Build.VERSION.SDK_INT >= 11) {
            this.f10219i.setAlpha(f);
        }
    }

    public void m14862c(int i) {
        if (this.f10214d) {
            this.f10218h.setBackgroundColor(i);
        }
    }

    public void m14863c(Drawable drawable) {
        if (this.f10215e) {
            this.f10219i.setBackgroundDrawable(drawable);
        }
    }

    public boolean m14864c() {
        return this.f10217g;
    }

    public void m14865d(int i) {
        if (this.f10214d) {
            this.f10218h.setBackgroundResource(i);
        }
    }

    public void m14866e(int i) {
        if (this.f10215e) {
            this.f10219i.setBackgroundColor(i);
        }
    }

    public void m14867f(int i) {
        if (this.f10215e) {
            this.f10219i.setBackgroundResource(i);
        }
    }
}

